#include "a2.hpp"

// Return a matrix to represent a counterclockwise rotation of "angle"
// degrees around the axis "axis", where "axis" is one of the
// characters 'x', 'y', or 'z'.
Matrix4x4 rotation(double angle, char axis)
{
  // Fill me in!
	Vector4D row1, row2, row3, row4;
	angle = angle/360*M_PI;
	switch( axis ){
		case 'x':
			row1 = Vector4D(1.0, 0.0, 0.0, 0.0);
			row2 = Vector4D(0.0, cos(angle), -sin(angle), 0.0);
			row3 = Vector4D(0.0, sin(angle), cos(angle), 0.0);
			row4 = Vector4D(0.0, 0.0, 0.0, 1.0);
			break;
		case 'y':
			row1 = Vector4D(cos(angle), 0.0, sin(angle), 0.0);
			row2 = Vector4D(0.0, 1.0, 0.0, 0.0);
			row3 = Vector4D(-sin(angle), 0.0, cos(angle), 0.0);
			row4 = Vector4D(0.0, 0.0, 0.0, 1.0);
			break;
		case 'z':
			row1 = Vector4D(cos(angle), -sin(angle), 0.0, 0.0);
			row2 = Vector4D(sin(angle), cos(angle), 0.0, 0.0);
			row3 = Vector4D(0.0, 0.0, 1.0, 0.0);
			row4 = Vector4D(0.0, 0.0, 0.0, 1.0);
			break;
	}
	return Matrix4x4(row1, row2, row3, row4);
}

// Return a matrix to represent a displacement of the given vector.
Matrix4x4 translation(const Vector3D& displacement)
{
	Vector4D row1( 1.0, 0.0, 0.0, displacement[0]);
	Vector4D row2( 0.0, 1.0, 0.0, displacement[1]);
	Vector4D row3( 0.0, 0.0, 1.0, displacement[2]);
	Vector4D row4( 0.0, 0.0, 0.0, 1.0);
	return Matrix4x4(row1, row2,row3, row4);
}

// Return a matrix to represent a nonuniform scale with the given factors.
Matrix4x4 scaling(const Vector3D& scale)
{
	Vector4D row1( scale[0], 0.0, 0.0, 0.0);
	Vector4D row2( 0.0, scale[1], 0.0, 0.0);
	Vector4D row3( 0.0, 0.0, scale[2], 0.0);
	Vector4D row4( 0.0, 0.0, 0.0, 1.0);
	return Matrix4x4(row1, row2,row3, row4);
}
